package com.culture.bootdemo.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

/**
 * @Author: wenjl
 * @Date: 2021/6/22 15:17
 * @Description: 重试
 */
@Service
@Slf4j
public class RetryService {

    /**
     * maxAttempts：重试次数
     * backoff：delay 每次重试延迟时间，单位毫秒
     * multiplier：假如是2，则每次2的倍数递增延迟时间
     */
    @Retryable(value = {Exception.class},
            maxAttempts = 5,
            backoff = @Backoff(delay = 1000, multiplier = 1))
    public void retryTest() {
        log.info("进来了。。。");
    }


    /**
     * 重试上限到达，调用此回调方法
     * 若要区分，可在传参中加入具体异常类
     */
    @Recover
    private void testRetryRecover() {
        log.info("方法重试失败次数到上限了");
    }

}
